/*
 * Copyright (C) 2010, Funcom AS, All Rights Reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @authors
 *  Svein Gunnar Larsen <sveingunnarlarsen@gmail.com>
 *  Erik Thune Lund <culex.eriklund@gmail.com>
 *  Michel Krohn-Dale <kronicz@gmail.com>
 */

package com.funcom.peeler.peelable;

import com.funcom.peeler.symbol.Symbol;
import com.jmex.bui.BLabel;
import org.w3c.dom.Element;

public class PeelLabel extends PeelTextComponent {

    public PeelLabel() {
        this( new BLabel( "Empty Label" ) );
    }

    protected PeelLabel( BLabel label ) {
        super( label );
        element_name = Symbol.Node.label;
    }

    protected Element getPeeledInfo( Element element ) {
        super.getPeeledInfo( element );

        Element text_element = element.getOwnerDocument().createElement( Symbol.Node.text_string);
        text_element.setAttribute( Symbol.Attr.text_string, ((BLabel)component).getText() );

        element.appendChild( text_element );

        return element;
    }

    protected void unpeelInfo( Element element ) {
        super.unpeelInfo( element );

        Element text_string_element = (Element)element.getElementsByTagName( Symbol.Node.text_string ).item(0);

        if ( text_string_element.hasAttribute( Symbol.Attr.text_string ) ) {
            String text_string = text_string_element.getAttribute( Symbol.Attr.text_string );

            ((BLabel)getComponent()).setText( text_string );
        }
    }
}
